package org.smoke.bean.enumerate;

import org.json.JSONObject;
import org.smoke.util.LangConfigUtil;


/**
 * @author hezhiyu on 14-9-23.
 */
public enum ApiStatus {

    // todo 相关返回值尚未补全, 格式模拟http协议的状态码 100 200 300 ....　易于拓展
    SUCCESS(0),

    /**
     * 用户相关
     */
    USER_EXIST(101),
    USER_AUTH_ERROR(102),
    EMAIL_ERROR(103),
    USER_NOT_EXIST(104),
    PASSWORD_ERROR(105),
    TOKEN_ERROR(106),

    /**
     * 业务相关
     */
    INVALID_INPUT(201),
    PASS_STRENGTH_LIMIT(202),
    EMAIL_INVALID(203),


    /**
     * 好友模块相关
     */
    FRIEND_RELATION_EXIST(301),
    FRIEND_COUNT_MAX(302),


    /**
     * Server ERROR
     */
    SERVER_ERROR(401);

    private int code;
    private JSONObject result;

    ApiStatus(int code) {
        this.code = code;
        result = new JSONObject();
        result.put("code", code);
//        result.put("msg", LangConfigUtil.getContent(this.name()));
        result.put("msg", "");
    }

    public JSONObject wrapper(Object res) {
        result.put("data", res);
        return result;
    }

    public int getCode() {
        return code;
    }

    @Override
    public String toString() {
        result.remove("data");
        return result.toString();
    }
}
